package deftoolbar

import "yunj/pkg/yunj/core/builder/builderaction"

// 自定义
type Custom struct {
	Action
}

// 自定义
func NewCustom(code any, title ...string) *Custom {
	a := &Custom{}

	builderaction.SetActionInstance(&a.Action.Action, a)
	a.SetActionCode(code)
	if len(title) > 0 {
		a.SetTitle(title[0])
	}
	return a
}

// 设置标题
func (a *Custom) SetTitle(title string) *Custom {
	a.Title = title
	return a
}

// 设置类型
func (a *Custom) SetType(typ string) *Custom {
	a.Type = typ
	return a
}

// 设置额外的class或图标类名
func (a *Custom) SetClass(class string) *Custom {
	a.Class = class
	return a
}

// 设置触发事件执行的url
func (a *Custom) SetUrl(url string) *Custom {
	a.Url = url
	return a
}

// 设置确认弹窗表单字段
// param: func() ([]form.FieldInterface, error)
// param: []form.FieldInterface
// param: form.FieldInterface
func (a *Custom) SetConfirmFormFields(param ...any) *Custom {
	builderaction.SetConfirmFormFields(&a.Action.Action, param...)
	return a
}

// 设置权限
func (a *Custom) SetAuth(auth string) *Custom {
	a.Auth = auth
	return a
}

// 处理属性
// func (a *Custom) HandleAttr() error {
// 	if a.Html == "" && a.HtmlFunc != nil {
// 		html, err := a.HtmlFunc(a)
// 		if err != nil {
// 			return a.SetError(err)
// 		}
// 		a.Html = html
// 	}
// 	return nil
// }
